<html><head>
<title>chat</title>
<script src="../../../closure/closure/goog/base.js"></script>
<script src="deps.js"></script>
<script>
  goog.require('ptucker.ChatAdmin');
  goog.require('goog.dom');
  goog.require('goog.testing.asserts');
  goog.require('goog.testing.jsunit');
</script>
</head><body>
<script>
  var ids = [];

  function setUp() {
    ids = [];
  }

  function tearDown() {
    for (var i = 0; i < ids.length; ++i) {
      var chatAdmin = new ptucker.ChatAdmin();
      chatAdmin.deleteRoom(ids[i]);
    }
  }

  function testNewRoom() {
    var chatAdmin = new ptucker.ChatAdmin();
    chatAdmin.newRoom('myRoomName', function(response) {
      assertTrue(goog.isNumber(response['response']));
    });
  }

  function testDeleteRoom() {
    var chatAdmin = new ptucker.ChatAdmin();
    chatAdmin.newRoom('myRoomName', function(response) {
      var id = response['response'];
      chatAdmin.deleteRoom(id, function(response) {
        assertEquals('Deleted room and 0 messages', response['response']);
      });
    });
  }

  function testRoomList() {
    var chatAdmin = new ptucker.ChatAdmin();
    chatAdmin.newRoom('myRoomName', function(response) {
      var id = response['response'];
      chatAdmin.roomList(null, function(response) {
        var rooms = response['rooms'];
        var found = false;
        assertTrue('no rooms returned', rooms && rooms.length);
        for (var i = 0; !found && i < rooms.length; ++i) {
          var room = rooms[i];
          if (room['id'] == id) {
            assertEquals('myRoomName', room['name']);
            assertUndefined(room['creatorEmail']);
            found = true;
          }
        }
        assertTrue('room not found', found);
      });
    });
  }
</script>
</body></html>
